#include "avpacketqueue.h"

AVPacketQueue::AVPacketQueue()
{

}

AVPacketQueue::~AVPacketQueue()
{

}

void AVPacketQueue::Abort()
{
    queue_.Abort();
}

void AVPacketQueue::Release()
{
    forever {
        AVPacket *pkt = nullptr;
        int ret = queue_.Pop(pkt, 1);
        if(ret < 0) {
            qDebug() <<" Release : "<< "";
            break;
        } else {
            av_packet_free(&pkt);
        }
    }
}

int AVPacketQueue::Size()
{
    return queue_.Size();
}

int AVPacketQueue::Push(AVPacket *val)
{
    AVPacket *tmp_pkt = av_packet_alloc();
    av_packet_move_ref(tmp_pkt, val);

    return queue_.Push(tmp_pkt);
}

AVPacket *AVPacketQueue::Pop(const int timeout)
{
    AVPacket *tmp_pkt = nullptr;
    int ret = queue_.Pop(tmp_pkt, timeout);
    if(ret < 0) {
        qDebug() <<" AVPacketQueue::Pop : "<< ret;
    }
    return tmp_pkt;
}
